package easier.window.popup.recycler;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;
import easier.window.Item;
import easier.window.popup.PopupWindowShow;
import easier.window.window.R;
import java.util.List;

/**
 * 弹出列表
 * 列表展示文字
 * 宽度等于锚点宽度
 * 文字靠左对齐
 */
public class PopupRecyclerViewImpl01 extends PopupRecyclerView< Item > {

    public PopupRecyclerViewImpl01( Context context ) {

        super( context );
    }

    @Override
    protected View createView( ViewGroup parent ) {

        return LayoutInflater.from( parent.getContext() ).inflate( R.layout.popup_window_check_recycler_item_1, parent, false );
    }

    @Override
    protected void onBindView( View view, int position, Item data ) {

        ((TextView) view.findViewById( R.id.text )).setText( data.getValue() );
    }

    /**
     * 自类实现该方法:完成数据通知
     *
     * @param v               点击了
     * @param adapterPosition 位置
     * @param item            数据
     */
    @Override
    protected void notifyViewClick( View v, int adapterPosition, Item item ) {

        dismiss();
    }

    @Override
    public void show( View anchor, List< Item > data ) {

        mRecycler.setAdapter( new Adapter( data ) );

        PopupWindowShow.showAsDropDown(
            this,
            anchor,
            anchor.getWidth(),
            LayoutParams.WRAP_CONTENT,
            0, 0,
            Gravity.BOTTOM
        );
    }
}